package org.arabidopsis.ahocorasick;

import java.util.Iterator;
import java.util.NoSuchElementException;

class Searcher implements Iterator {
    private SearchResult currentResult;
    private final AhoCorasick tree;

    Searcher(AhoCorasick tree, SearchResult result) {
        this.tree = tree;
        this.currentResult = result;
    }

    public boolean hasNext() {
        return (this.currentResult != null);
    }

    public Object next() {
        if (!hasNext())
            throw new NoSuchElementException();
        Object result = this.currentResult;
        this.currentResult = this.tree.continueSearch(this.currentResult);
        return result;
    }

    public void remove() {
        throw new UnsupportedOperationException();
    }
}
